using System;
using System.Collections;
using System.IO;
using UnityEngine;

public class Platform : MonoBehaviour
{
	public static string[] notification = new string[4]
	{
		"Enemy is coming! Ready for fight!",
		"Your power is full, don't waste it!",
		"Hey! Take these daily reward!",
		"Hey soldier! New mission! Don't be lazy!"
	};

	public static string[] coinSkus = new string[14]
	{
		"coin_199",
		"coin_499",
		"coin_999",
		"coin_1999",
		"coin_4999",
		"coin_9999",
		"gold_199",
		"gold_499",
		"gold_999",
		"gold_1999",
		"gold_4999",
		"gold_9999",
		"sale_499",
		"sale_999"
	};

	public static int[] coinCount = new int[12]
	{
		5000,
		13000,
		30000,
		65000,
		170000,
		350000,
		50,
		130,
		300,
		650,
		1700,
		3500
	};

	public static bool[] adsFree = new bool[14]
	{
		false,
		true,
		true,
		true,
		true,
		true,
		false,
		true,
		true,
		true,
		true,
		true,
		true,
		true
	};

	public static bool IsHaveshowFakeLoadingover;

	private static Platform _instance;

	private int timecount;

	public static AndroidJavaClass jc;

	public static AndroidJavaObject currentActivity;

	public static Platform Instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = (UnityEngine.Object.FindObjectOfType(typeof(Platform)) as Platform);
				if (_instance == null)
				{
					_instance = new GameObject("Platform").AddComponent<Platform>();
					_instance.Awake();
					UnityEngine.Object.DontDestroyOnLoad(_instance.gameObject);
				}
			}
			return _instance;
		}
	}

	public void OnPurchaseSuccess(string skuId)
	{
		if (skuId == null)
		{
			return;
		}
		int num = 0;
		while (true)
		{
			if (num < coinSkus.Length)
			{
				if (skuId.Equals(coinSkus[num]))
				{
					break;
				}
				num++;
				continue;
			}
			return;
		}
		if (num < 6)
		{
			MenuPlayerprefs.instance.AddMoney(coinCount[num]);
		}
		else if (num < 12)
		{
			MenuPlayerprefs.instance.AddDiamod(coinCount[num]);
		}
		else
		{
			MenuPlayerprefs.instance.ForSaleGive(num);
		}
		MenuUIController.instance.chargeui.setAdfree();
		flurryEvent_onCharge(num);
	}

	public void HideFullScreenSmallFromAndroid()
	{
		if (MenuBackController.instance != null && MenuBackController.instance.curstate == MenuUIState.exitui)
		{
			MenuUIController.instance.exitui.setclosepos();
		}
	}

	private void Awake()
	{
		if (_instance == null)
		{
			_instance = this;
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		}
		else if (_instance != this)
		{
			UnityEngine.Object.Destroy(base.gameObject);
			return;
		}
		Init();
		CreateBilling();
	}

	private void Update()
	{
		if (!IsHaveshowFakeLoadingover)
		{
			timecount++;
			if (GetTimeLeft() <= 0 && timecount > 30)
			{
				IsHaveshowFakeLoadingover = true;
				HideFakeLoading();
				ShowFullScreenSmall();
			}
		}
	}

	private void Init()
	{
		if (Debug.isDebugBuild)
		{
			currentActivity = null;
		}
		else if (currentActivity == null)
		{
			//jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
			//currentActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
		}
	}

	public void CreateBilling()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalCreateBilling");
		}
	}

	public static void Billing(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalBilling", id);
		}
	}

	public static bool IsUnityAdsCanShow()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<bool>("IsUnityAdsCanShow", new object[0]);
		}
		return false;
	}

	public static bool IsUnityAdsReady()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<bool>("IsUnityAdsReady", new object[0]);
		}
		return false;
	}

	public static bool ShowRewardVideoUnityAds()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("ShowRewardVideoUnityAds");
		}
		return false;
	}

	public void UnityAdsReadyBack()
	{
		if (MenuUIController.instance != null && MenuUIController.instance.upgradeui != null)
		{
			MenuUIController.instance.uplineui.ShowAdsBtn();
		}
	}

	public void UnityAdsCallBack()
	{
		MenuUIController.instance.enable_adreward();
		MenuPlayerprefs.SaveAdTimes();
		MenuUIController.instance.uplineui.ShowAdsBtn();
	}

	public static void ShowFeatureView()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalShowFeatureView");
		}
	}

	public static void HideFeatureView()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalHideFeatureView");
		}
	}

	public static bool IsFullScreenSmallReady()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<bool>("internalIsFulScreenSmallReady", new object[0]);
		}
		return false;
	}

	public static bool IsFullScreenSmallShowing()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<bool>("internalIsFullScreenSmallShowing", new object[0]);
		}
		return false;
	}

	public static void ShowFullScreenExitSmall()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalShowFullScreenExitSmall");
		}
	}

	public static void ShowFullScreenSmall()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalShowFullScreenSmall");
		}
	}

	public static void HideFullScreenSmall()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalHideFullScreenSmall");
		}
	}

	public static bool IsAdsFree()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<bool>("internalIsAdsFree", new object[0]);
		}
		return false;
	}

	public static void SetAdsFree()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("setAdsFree", true);
		}
	}

	public static long GetTimeLeft()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<long>("internalGetTimeLeft", new object[0]);
		}
		return -1L;
	}

	public static void HideFakeLoading()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalHideFakeLoading");
		}
	}

	public static long GetServerTime()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<long>("internalGetServerTime", new object[0]);
		}
		return -1L;
	}

	public static void ShowMoreGames()
	{
		if (currentActivity != null)
		{
			flurryEvent_main(-1, 0);
			currentActivity.Call("internalMoreGames");
		}
	}

	public static void Rating()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalRating");
		}
	}

	public static int GetBonusCount()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<int>("internalGetBonusCount", new object[0]);
		}
		return -1;
	}

	public static int GetBonusAlreadyGot()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<int>("internalGetBonusAlreadyGet", new object[0]);
		}
		return -1;
	}

	public static void SetBonusCount()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalSetBonusCount");
		}
	}

	public static string GetPhoneModel()
	{
		if (currentActivity != null)
		{
			return currentActivity.Call<string>("getModel", new object[0]);
		}
		return string.Empty;
	}

	public static void ShareImage(string imagePath, string text, int extraData)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("shareImage", imagePath, text, extraData);
		}
	}

	public static void ToastLong(string toastString)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("showToastLong", toastString);
		}
	}

	public static void ToastShort(string toastString)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("showToastShort", toastString);
		}
	}

	public static void setNotification(int nt, int hasGetReward, long delay, string message)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalSetNotification", nt, hasGetReward, delay, "Sky Fighters", message);
		}
	}

	public static void cancleNotification(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("internalCancelNotification", id);
		}
	}

	public static void cancleAllNotification()
	{
		if (currentActivity != null)
		{
			for (int i = 0; i < 7; i++)
			{
				cancleNotification(i);
			}
		}
	}

	public static void flurryEvent_guide_first(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_guide_first", id);
		}
	}

	public static void flurryEvent_guide_first_game(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_guide_first_game", id);
		}
	}

	public static void flurryEvent_guide_rate()
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_guide_rate");
		}
	}

	public static void flurryEvent_level(int level, int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_level", level, id);
		}
	}

	public static void flurryEvent_buylevel(int lv)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_buylevel", lv);
		}
	}

	public static void flurryEvent_challenge(int modeid, int type, int even)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_challenge", modeid, type, even);
		}
	}

	public static void flurryEvent_ffa(int rank)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_ffa", rank);
		}
	}

	public static void flurryEvent_sur(int ww)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_sur", ww);
		}
	}

	public static void flurryEvent_plane(int ww)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_plane", ww);
		}
	}

	public static void flurryEvent_store(int type, int weaponid, int even)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_store", type, weaponid, even);
		}
	}

	public static void flurryEvent_onCharge(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_onCharge", id);
		}
	}

	public static void flurryEvent_achievement(int id, int star)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_achievement", id, star);
		}
	}

	public static void flurryEvent_main(int type, int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_main", type, id);
		}
	}

	public static void flurryEvent_box(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_box", id);
		}
	}

	public static void flurryEvent_dailytask(int id)
	{
		if (currentActivity != null)
		{
			currentActivity.Call("flurryEvent_dailytask", id);
		}
	}

	public IEnumerator TakeScreenshot(Action onStart, Action<string> onFinish)
	{
		onStart?.Invoke();
		yield return new WaitForEndOfFrame();
		ToastLong("Wait a moment, we are taking a photo..");
		int width = Screen.width;
		int height = Screen.height;
		Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, mipChain: false);
		tex.ReadPixels(new Rect(0f, 0f, width, height), 0, 0);
		tex.Apply();
		byte[] screenshot = tex.EncodeToPNG();
		string imagePath = Application.persistentDataPath + "/" + DateTime.Now.ToFileTime().ToString() + ".png";
		File.WriteAllBytes(imagePath, screenshot);
		onFinish?.Invoke(imagePath);
	}

	public void OnApplicationQuit()
	{
		UnityEngine.Object.Destroy(base.gameObject);
		_instance = null;
	}
}
